/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wiView.graphics.Drawer;

import java.util.ArrayList;
import wiBase.baseObject.Node;
import wiView.graphics.GraphObject.*;
import wiView.graphics.Drawer.NetworkEventDispatcher.EventDispatcher;
import wiEngine.WiEngine;
import wiView.graphics.Drawer.GraphAnimation.AnimationHandle;
/**
 *
 * @author Hoang
 */
public class _Drawer extends AbstractDrawer{

    protected WiGraph graph;
    protected WiEngine engine;
    public _Drawer(WiGraph g){
        graph = g;
        
    }
    public void setEngine(WiEngine e){
        engine = e;
        eventDispatcher = new EventDispatcher(graph, e);
        animationHandle = new AnimationHandle(graph, e);
    }
    public void setSpeed(int s){
        AnimationHandle ah = (AnimationHandle)animationHandle;
        ah.setSpeed(s);
    }
    public int getSpeed(){
        AnimationHandle ah = (AnimationHandle)animationHandle;
        return ah.getSpeed();
    }
    @Override
    public void DrawNodes(ArrayList<Node> nodes) {
        if (nodes == null || graph == null) {
	    return;
	}
        
	for (int i = 0; i < nodes.size(); i++) {
	    wiBase.baseObject.Node node = (wiBase.baseObject.Node) nodes.get(i);
	    wiNode n = graph.addwiNode(node.id + "");
            n.setCoordinate(node.position.getX() * 16 / 9, node.position.getY());
            n.setLabel(Integer.toString(node.id));
            n.setState(wiNode.State.Wake);
	    
	}
    }
    boolean isRunning = false;
    @Override
    public void Start() {
        if(!isRunning){
            animationHandle.Start();
            isRunning = true;
        }
    }

    @Override
    public void Stop() {
        animationHandle.Stop();
    }
    public void resetGraph(){
        AnimationHandle ah = (AnimationHandle)animationHandle;
        ah.clean();
        graph.resetKeepNodes();
        for (org.graphstream.graph.Node node : graph.getNodeSet()) {
            graph.getwiNode(node.getId()).setState(wiNode.State.Wake);
        }
    }
}
